package com.thread;

/**
 * Created by Administrator on 2018/5/28.
 */
public class MyThread{

    private Object object = new Object();
    private int i = 10;

    public static void main(String[] args) {
        MyThread thread = new MyThread();
        Test test = thread.new Test();
        Test test1 = thread.new Test();
//        test.start();
//        test1.start();
        Thread thread1 = new Thread(test);
        Thread thread2 = new Thread(test1);
        thread1.start();
        thread2.start();

    }

    class Test extends Thread{

        @Override
        public void run() {
            synchronized (object){
                i ++;
                System.out.println("i:" + i);
                try {
                    System.out.println("线程" + Thread.currentThread().getName() + "进入睡眠状态");
                    Thread.currentThread().sleep(10000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("线程" + Thread.currentThread().getName() + "睡眠结束");
                i++;
                System.out.println("i:" + i);

            }
        }
    }

}
